#include<stdio.h>
#include<time.h>

// 0-clubs, 1-spades, 2-diamonds, 3-hearts
// 0-2, 3, 4, 5, 6, 7, 8, 9, 8-10, 9-j, 10-q, 11-k, 12-a
const char num[13][3] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"};
const char suit[4][9] = {"clubs", "spades", "diamonds", "hearts"};

void printCard(int num_id, int suit_id, char* p)
{
    printf("%s gets the %s of %s.\n", p, num[num_id], suit[suit_id]); 
}

int main(){

   int cards[52][2];
    for(int i=0, j=-1;i<52;i++)
    {
        if(i%4 == 0)
        {
            j++;
        }
        cards[i][0] = j;
        cards[i][1] = i % 4;
    }
    srand((unsigned int)time(NULL));
    int offset, player1, player2;
    do
    {
//        srand((unsigned int)time(NULL));
        offset = rand() % 10;
//        srand((unsigned int)time(NULL));
        player1 = rand() % 52;
//        srand((unsigned int)time(NULL) + offset);
        player2 = rand() % 52;
        if(player1 == player2)
        {
            printf("There is a tie.\n");
        }
    }
    while(player1 == player2);
    printCard(cards[player1][0], cards[player1][1], "Player1");
    printCard(cards[player2][0], cards[player2][1], "Player2");
    if(cards[player1][0] > cards[player2][0])
    {
        printf("Player 1 wins.\n");
    }
    else if(cards[player1][0] < cards[player2][0])
    {
        printf("Player 2 wins.\n");
    }
    else
    {
        if(cards[player1][1] > cards[player2][1]) 
        {
            printf("Player 1 wins.\n");
        }
        else
        {
            printf("Player 2 wins.\n");   
        }
    }
return 0;
}
